<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ThemeScan.php 323 2008-12-01 18:32:53Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalToDoRecord');
Prado::using('Application.Common.Data.PortalThemeRecord');

class ThemeScan extends PortalAdminPage
{
	public function dataBind()
	{
		$newthemes	= array();
		$cdb		= $this->Application->DbConnection;
		$errors		= array();

		// Scan /Pages for pages to add
		$pagesdir   = str_replace("\\", "/",$this->Application->PortalBasePath . "/themes/Portal");
		$themes		= array_diff(scandir($pagesdir. '/'), array('.', '..', '.svn','System','Admin','Install')); // remove ' and .. from the array

		if(is_array($themes) && count($themes) > 0)
		{
			foreach($themes as $theme)
			{
				$ptr = PortalThemeRecord::finder()->findByname($theme);

				if(!$ptr)
				{
					$newthemes[]['name'] = $theme;

					$ptr			= new PortalThemeRecord();
					$ptr->name		= $theme;
					$ptr->active	= 1;
					$ptr->save();
				}
			}
		}

		if(count($newthemes) > 0)
		{
			$this->Repeater->Visible	= true;
			$this->Repeater->Enabled	= true;
			$this->Repeater->DataSource	= $newthemes;
			$this->Repeater->dataBind();
		}
		else
		{
			$this->Repeater->Visible		= false;
			$this->Repeater->Enabled		= false;
			$this->pnlNoNewThemes->Visible	= true;
			$this->pnlNoNewThemes->Enabled	= true;
		}
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		if(!$this->IsPostBack)
		{
			$this->dataBind();
		}
	}

	public function GetCssStyle($item)
	{
		switch($item->priority)
		{
			case 0:	return 'background-color:#FFFF80';break;
			case 1:	return 'background-color:#80FF80';break;
			case 2:	return 'background-color:#FF8080';break;
		}
	}
}
?>